import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
  selector: 'wf-add-port-modal',
  templateUrl: './add-port-modal.component.html',
  styleUrls: ['./add-port-modal.component.less'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AddPortModalComponent implements OnInit {

  form!: FormGroup;
  @Input() item: any;

  constructor(
    private fb: FormBuilder,
    private modalRef: NzModalRef,
  ) {
    this.form = this.fb.group({
      name: [null, []],
    });
  }

  ngOnInit(): void {
    if (this.item) { // 编辑
      this.form.addControl('id', this.fb.control(null));
      this.form.patchValue(this.item);
    }
  }

  submit() {
    this.modalRef.destroy(this.form.value);
  }
}
